<?php

	include("common.php");
	
	$files = array();
	$handle = opendir('../files/');
	while(false !== ($file = readdir($handle))){
		array_push($files, $file);
	}
	
?>
<?php include("header.php"); ?>
<h1>修改／刪除檔案</h1>
<div id="delete-file-dialog">
	<p>確定刪除？</p>
</div>
<script type="text/javascript" defer="defer">
	$("#delete-file-dialog").dialog({
		width: 300,
		height: 210,
		autoOpen: false,
		title: "刪除檔案",
		modal: true,
		draggable: false,
		resizable: false
	});
	$("#file-link-dialog").dialog({
		width: 500,
		height: 210,
		autoOpen: false,
		title: "檔案連結",
		modal: true,
		draggable: false,
		resizable: false
	});
	function showConfirm(file_name){
		$("#delete-file-dialog").dialog("option", "buttons", {"確定": function(){ $(this).dialog("close"); deleteFile(file_name); }, "取消": function(){ $(this).dialog("close"); }
		}).dialog("open");
	}
	function deleteFile(file_name){
		$("#delete-file-dialog").dialog("option", "buttons", { "關閉": function(){ location.reload(); } });
		$("#delete-file-dialog").html("<img src='../images/ajax-loader.gif' />");
		$("#delete-file-dialog").dialog("open");
		$("#delete-file-dialog").load("fileDelete.php?file_name=" + file_name + "&ajax=true");
	}
</script>
<?php if(empty($files)){ ?>
	<p>目前沒有檔案。</p>
<?php } else { ?>
	<ul>
		<?php foreach($files as $row){ if(!is_dir("../files/" . $row)){ ?>
		<li><?php echo $row; ?> - [ <a href="fileEdit.php?file_name=<?php echo $row; ?>">編輯</a>｜<a href="fileDelete.php?file_name=<?php echo $row; ?>" onclick="showConfirm('<?php echo $row; ?>'); return false;">刪除</a> ]</li>
		<?php } } ?>
	</ul>
<?php } ?>
<p><a href="fileAdd.php">上傳檔案</a></p>
<?php include("sidebar.php"); ?>
<?php include("footer.php"); ?>